//
//  QRCodeTool.m
//  quanyouzhensuo
//
//  Created by 爱你婚纱摄影 on 2018/10/31.
//  Copyright © 2018年 爱你婚纱摄影. All rights reserved.
//

#import "QRCodeTool.h"
#import <AVFoundation/AVFoundation.h>
#import <CoreImage/CoreImage.h>

static QRCodeTool *_qrCodeTool;

@interface QRCodeTool ()

@end

@implementation QRCodeTool

+ (instancetype)share {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _qrCodeTool = [[QRCodeTool alloc] init];
    });
    return _qrCodeTool;
}

- (UIImage *)createWithBgImage:(UIImage *)bgImage logoImageSize:(CGFloat)waterImagesize {
    //原图
    UIImage *outputImage = bgImage;
    //给二维码加 logo 图
    UIGraphicsBeginImageContextWithOptions(outputImage.size, NO, [[UIScreen mainScreen] scale]);
    [outputImage drawInRect:CGRectMake(0,0 , bgImage.size.width, bgImage.size.height)];
    //logo图
    UIImage *waterimage = [UIImage imageNamed:@"下载"];//head
    //把logo图画到生成的二维码图片上，注意尺寸不要太大（最大不超过二维码图片的%30），太大会造成扫不出来
    [waterimage drawInRect:CGRectMake((bgImage.size.width-waterImagesize)/2.0, (bgImage.size.height-waterImagesize)/2.0, waterImagesize, waterImagesize)];
    UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newPic;
}

- (UIImage *)createWithBgImage:(UIImage *)bgImage contentImage:(UIImage *)contentImage {
    
    UIGraphicsBeginImageContextWithOptions(bgImage.size, NO, [[UIScreen mainScreen] scale]);
    [bgImage drawInRect:CGRectMake(0,0 , bgImage.size.width, bgImage.size.height)];
    [contentImage drawInRect:CGRectMake(10.0, 10.0, bgImage.size.width - 10.0 * 2, (bgImage.size.width - 10.0 * 2) / (contentImage.size.width / contentImage.size.height))];
    
    UIImage *qrImg = [UIImage imageNamed:@""];
     
    UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newPic;
}

@end
